package com.atdel.demo18;


import org.junit.Test;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;

/**
 * @BelongsProject: java_study
 * @BelongsPackage: com.atdel.demo18
 * @Author: Del
 * @CreateTime: 2025-03-17  15:47
 * @Description:
 * 遍历Integer类中所有的字段，格式如下所示
 *       public final class Integer {
 *           public static final int MIN_VALUE;
 *           public static final int MAX_VALUE;
 *           public static final Class TYPE;
 *           static final char[] digits;
 *           static final char[] DigitTens;
 *           static final char[] DigitOnes;
 *           static final int[] sizeTable;
 *           private final int value;
 *           public static final int SIZE;
 *           public static final int BYTES;
 *           private static final long serialVersionUID;
 *       }
 * @Version: 1.0
 */
public class ReflectDemo {
    @Test
    public void test() {
        // 获取系统类加载器
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
        try {
            // 加载类
            Class<?> aClass = systemClassLoader.loadClass("java.lang.Integer");
            // 获取所有的字段
            Field[] declaredFields = aClass.getDeclaredFields();
            // 遍历所有的字段
            for (Field declaredConstructor : declaredFields) {
                System.out.println(declaredConstructor);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}
